package com.ruoyi.system.service.impl;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.domain.WarehousePermission;
import com.ruoyi.system.mapper.WarehousePermissionMapper;
import com.ruoyi.system.service.IWarehousePermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 仓库权限Service业务层处理
 *
 * @author ruoyi
 * @date 2025-10-09
 */
@Service
public class WarehousePermissionServiceImpl implements IWarehousePermissionService {
    @Autowired
    private WarehousePermissionMapper warehousePermissionMapper;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询仓库权限
     *
     * @param id 仓库权限主键
     * @return 仓库权限
     */
    @Override
    public WarehousePermission selectWarehousePermissionById(Long id) {
        return warehousePermissionMapper.selectWarehousePermissionById(id);
    }

    /**
     * 查询仓库权限列表
     *
     * @param warehousePermission 仓库权限
     * @return 仓库权限
     */
    @Override
    public List<WarehousePermission> selectWarehousePermissionList(WarehousePermission warehousePermission) {
        return warehousePermissionMapper.selectWarehousePermissionList(warehousePermission);
    }

    /**
     * 新增仓库权限
     *
     * @param warehousePermission 仓库权限
     * @return 结果
     */
    @Override
    public int insertWarehousePermission(HttpServletRequest request, WarehousePermission warehousePermission) {
        LoginUser user = tokenService.getLoginUser(request);
        warehousePermission.setCreatorId(user.getUserId());
        warehousePermission.setCreateTime(DateUtils.getNowDate());
        return warehousePermissionMapper.insertWarehousePermission(warehousePermission);
    }

    /**
     * 修改仓库权限
     *
     * @param warehousePermission 仓库权限
     * @return 结果
     */
    @Override
    public int updateWarehousePermission(WarehousePermission warehousePermission) {
        return warehousePermissionMapper.updateWarehousePermission(warehousePermission);
    }

    /**
     * 批量删除仓库权限
     *
     * @param ids 需要删除的仓库权限主键
     * @return 结果
     */
    @Override
    public int deleteWarehousePermissionByIds(Long[] ids) {
        return warehousePermissionMapper.deleteWarehousePermissionByIds(ids);
    }

    /**
     * 删除仓库权限信息
     *
     * @param id 仓库权限主键
     * @return 结果
     */
    @Override
    public int deleteWarehousePermissionById(Long id) {
        return warehousePermissionMapper.deleteWarehousePermissionById(id);
    }
}
